home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1995 November / Macworld Nov ’95.toast / Developers / Selection ƒ 2.5 / rect+ < prev    next >
Encoding:
Text File  |  1994-11-06  |  1.4 KB  |  67 lines  |  [TEXT/MSET]

  1. (*
  2. A rect+ is simply a rect that initializes its data to something other
  3. than zero.  We also add some additional methods.
  4. *)
  5.  
  6.  
  7. :class rect+ super{ rect }
  8. \ DO NOT change the ivar mapping for rect+ because we use it extensively
  9. \ for mapping into toolbox records.
  10.  
  11. :m classinit:    \ let's always start with a non-null rectangle
  12.     50 50 100 100 put: super ;m
  13.  
  14. :m move: { dx dy -- }
  15.     self  dx dy pack call OffsetRect ;m
  16.  
  17. :m moveto: { l t -- }
  18.     l t
  19.     size: super ( l t width height)
  20.     t +  ( l t width b )
  21.     swap ( l t b width )
  22.     l +  ( l t b r )
  23.     swap
  24.     put: self ;m
  25.  
  26. :m erase:
  27.     clear: super ;m
  28.  
  29.  
  30. \ rectangle coordinate access methods in 2-point form (x1,y1,x2,y2)
  31. :m getx1: ( -- x1)  getx: topl ;m
  32. :m putx1: ( x1 -- )  putx: topl ;m
  33. :m gety1: ( -- y1)  gety: topl ;m
  34. :m puty1: ( y1 -- )  puty: topl ;m
  35.  
  36. :m getx2: ( -- x2)  getx: botr ;m
  37. :m putx2: ( x2 --  )  putx: botr ;m
  38. :m gety2: ( -- y2)  gety: botr ;m
  39. :m puty2: ( y2 --  )  puty: botr ;m
  40.  
  41. :m getx1y1: ( -- x1 y1 ) get: topl ;m
  42. :m putx1y1: ( x1 y1 -- ) put: topl ;m
  43.  
  44. :m getx2y2: ( -- x2 y2 ) get: botr ;m
  45. :m putx2y2: ( x2 y2 -- ) put: botr ;m
  46.  
  47. :m width: ( -- w )
  48.     getx2: self  getx1: self - ;m
  49.  
  50. :m height: ( -- h )
  51.     gety2: self  gety1: self - ;m
  52.  
  53. :m setwidth: ( w -- )    \ will change x2 only
  54.     getx1: self + putx2: self ;m
  55.  
  56. :m setheight: ( h -- )    \ will change y2 only
  57.     gety1: self + puty2: self ;m
  58.  
  59. ;class
  60.  
  61. endload
  62.  
  63. *** EXAMPLE USE
  64.  
  65. rect+ r
  66. draw: r
  67.